package com.yd.mvc.pc.cartController;

import com.yd.app.service.pc.userCartService.UserCartService;
import com.yd.domain.business.ShoppingCart;
import com.yd.mvc.baseController.util.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by bxd on 2018/3/21.
 */
@RestController
@RequestMapping(value = "/api/usercart")
public class CartController {
    @Autowired
    private UserCartService userCartService;
    /**
     * 添加
     *
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public void addUserCart(@RequestBody ShoppingCart shoppingCart) throws BootstrapMethodError{
        userCartService.addCart(shoppingCart);
    }

    /**
     * 修改
     *
     */
  /*  @RequestMapping(value = "/update", method = RequestMethod.POST)
    public void updateUserCart(@RequestBody ShoppingCart shoppingCart) {
        userCartService.updateCart(shoppingCart);
    }*/

    /**
     * 删除
     *
     */
    @RequestMapping(value = "/delete/{userId}/{goodsId}/{goodsWeightId}", method = RequestMethod.POST)
    public void deleteUserCart(@PathVariable("userId") String userId, @PathVariable("goodsId") String goodsId,String goodsWeightId) {
        userCartService.deleteCart(userId, goodsId,goodsWeightId);
    }

    /**
     * 查询用户购物车信息
     *
     */
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    public List<ShoppingCart> getListCart() {
        String userId=AuthUtil.getCurrentUser().getUserId();
        List<ShoppingCart> list= userCartService.getListCart(userId);
        return list;
    }
}
